package com.cz.basetool;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import android.util.Log;

import com.cz.basetool.test.TestAbsQueueTaskHelper;
import com.cz.basetool.ui_work.thread.MainHandler;
import com.cz.basetool.ui_work.util.data.AbsQueueTaskHelper;
import com.cz.basetool.ui_work.util.log.AndroidConsoleLogPrinter;
import com.cz.basetool.ui_work.util.log.CZLocalLogPrinter;
import com.cz.basetool.ui_work.util.safe.FileEncrypter;

import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;

/**
 * Instrumented test, which will execute on an Android device.
 *
 * @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
 */
@RunWith(AndroidJUnit4.class)
public class ExampleInstrumentedTest {
    @Test
    public void useAppContext() {
        // Context of the app under test.
        Context appContext = InstrumentationRegistry.getTargetContext();

        assertEquals("com.cz.basetool.test", appContext.getPackageName());


    }


    @Test
    public void testAbsQueueTaskHelper() {
        TestAbsQueueTaskHelper.getInstance().init();
        TestAbsQueueTaskHelper.getInstance().setOnTaskActivateListener(new AbsQueueTaskHelper.OnTaskActivateListener() {
            @Override
            public void onTaskActivate(Object item) {
                AndroidConsoleLogPrinter.d("TestAbsQueueTaskHelper", "onTaskActivate: 执行任务---" + item);
                MainHandler.getInstance().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        TestAbsQueueTaskHelper.getInstance().next();
                    }
                },100);
            }
        });
        new Thread(){
            @Override
            public void run() {
                //模拟读取数据，加入队列。
                TestAbsQueueTaskHelper.getInstance().join("1111");
                TestAbsQueueTaskHelper.getInstance().join("2222");
                TestAbsQueueTaskHelper.getInstance().join("3333");
            }
        }.start();
    }

    @Test
    public void testDialer() {
        String encrypt = FileEncrypter.encrypt("2019/05/15 20:21:46#PowerManager:上电初始化\ndsfayupy范德萨水立方的空间啊发");
        System.out.println("encrypt = " + encrypt);
    }
}
